package org.softmed.rest.server.test.creators.testcases.parameters;

import org.restlet.data.Response;
import org.restlet.data.Status;
import org.softmed.rest.server.test.creators.AbstractTestCaseCreator;

public class GetFieldNameText extends AbstractTestCaseCreator {

	boolean createTestResult;
	String fieldName;
	String expectedValue;

	public GetFieldNameText(String fieldName, String expectedValue,
			boolean createTestResult) {
		this.fieldName = fieldName;
		this.expectedValue = expectedValue;
		this.createTestResult = createTestResult;
	}

	@Override
	public String testCase(String uri, String elementURI) throws Throwable {

		Response response = creator.get(elementURI + "/" + fieldName);
		if (expectedValue != null) {
			if (!response.getStatus().equals(Status.SUCCESS_OK))
				return elementURI;

			if (!expectedValue.equalsIgnoreCase(creator.getTestCase()
					.getResponse().getBody()))
				return elementURI;

		} else {
			if (!response.getStatus().equals(Status.CLIENT_ERROR_NOT_FOUND))
				return elementURI;
		}

		creator.getTestCase().setSucess(true);

		return elementURI;
	}

}
